<?php

/**
 * Form for editing child data
 */
class Application_Form_Child extends Zend_Form
{

    // Mapping keys to db columns
    private static $DB_MAPPING = array(
	"gender" => "gender",
	"forename" => "forename",
	"surname" => "surname",
	"birthday" => "birthday",
	"points" => "ranking_points",
	"comment" => "comment"
    );
    // Mapping Max Length from db
    private static $MAX_LENGTH = array(
	"forename" => "50",
	"surname" => "70",
	"comment" => "2500",
    );

    public function init()   
    {
	$this->setMethod('post');

	//Validators
	$valid_notempty = new Zend_Validate_NotEmpty();
	$valid_date = new Zend_Validate_Date(array('format' => 'dd.mm.yyyy',));
	$valid_date_earlier = new Fkb_Validate_DateEarlier();
	$valid_own_alpha = new Zend_Validate_Regex(array('pattern' => '~^[A-ZÄÖÜa-zäöüß]+([-, ][A-ZÄÖÜa-zäöüß]+)*$~i'));
	$valid_own_alpha->setMessage(' %value% ist nicht erlaubt. Erlaubte Zeichen: a-z, äüöß,  , - ');


	$this->addElement('select', $this::$DB_MAPPING['gender'], array(
	    'label' => 'Geschlecht:*',
	    'required' => true,
	    'MultiOptions' => (array(
	"Weiblich" => "weiblich",
	"Männlich" => "männlich")),
	    'validators' => array()
	));

	$this->addElement('text', $this::$DB_MAPPING['forename'], array(
	    'label' => 'Kind Vorname:*',
	    'required' => true,
	    'filters' => array('StringTrim'),
	    'validators' => array($valid_notempty, $valid_own_alpha,
		array("StringLength", false,
		    array('max' => $this::$MAX_LENGTH['forename']))
	    )
	));

	$this->addElement('text', $this::$DB_MAPPING['surname'], array(
	    'label' => 'Kind Nachname:*',
	    'required' => true,
	    'filters' => array('StringTrim'),
	    'validators' => array($valid_notempty, $valid_own_alpha,
		array("StringLength", false,
		    array('max' => $this::$MAX_LENGTH['surname']))
	    )
	));

	$this->addElement('text', $this::$DB_MAPPING['birthday'], array(
	    'label' => 'Kind Geburtstag (dd.mm.yyyy ):*',
	    'required' => true,
	    'filters' => array('StringTrim'),
	    'validators' => array($valid_notempty, $valid_date, $valid_date_earlier)
	));

	$this->addElement('text', $this::$DB_MAPPING['points'], array(
	    'label' => 'Kind Ranking Points:*',
	    'required' => true,
	    'filters' => array('StringTrim'),
	    'validators' => array($valid_notempty,
		array('validator' => 'Int','options' => array('messages'=>' %value% ist nicht erlaubt. Erlaubte Zeichen sind 0-9'))
	    )
	));

	$this->addElement('textarea', $this::$DB_MAPPING['comment'], array(
	    'label' => 'Bitte ein Kommentar:',
	    'required' => false,
	    'validators' => array($valid_notempty,
		array("StringLength", false,
		    array('max' => $this::$MAX_LENGTH['comment']))
	    )
	));
    }

}
